<?php
header("Content-Type: text/html; charset=iso-8859-1");
require 'include.php';
$_SESSION['navigation'] = 'contacts';
$commissions = liste('commissions');
$script = "";
if(check_admin() && is_ie6() == 0){
	foreach($commissions as $id => $nom){
		$script .=  " function rank_$nom(){\n";
		$script .=  " 	var options = {\n";
		$script .=  " 	                method : 'post',\n";
		$script .=  " 	                parameters : Sortable.serialize('table_content_$nom')\n";
		$script .=  " 	              };\n";
		$script .=  " 	if($('table_content_$nom')) new Ajax.Request('commission_admin.php?commission=$id', options);\n";
		$script .=  " }\n";
	}
}
entete("Contacts",$script);
$q = "select tel, mobile from membres left join membre_commissions on membres.id = membre_id where fonction = 'Président'";
$r = ExecRequete($q);
if($s = LigneSuivante($r)){
	$tel = $s->tel;
	$mobile = format_tel($s->mobile);
}
else{
	$tel = ""; $mobile = "";
}
echo "<h1>Contacts</h1>\n";
echo "<h2><a name = 'adresse'></a>Adresse du club</h2>\n";
echo "<table><tr><th></th><th>Adresse</th><th>T&eacute;l&eacute;phones</th><th>email</th></tr>\n";
echo "<tr><td class = 'bold'>Volley-Ball Club Lutry-Lavaux</td><td class = 'center'>Case postale 47<br />1095 Lutry</td><td class = 'center'>$tel<br />$mobile</td><td class = 'center'>".(print_email("comite@vbcll.ch"))."</td></tr>\n";
echo "</table>\n";
echo "<h2><a name = 'salles'></a>Salles de sports</h2>\n";
$salles = get_salles_lutry();
$fields = array("No" => "no",
				"Nom" => "nom",
				"Adresse" => "adresse,localite",
				"Carte" => "carte");

$table = new table('salles');
$table->filter = 0;
foreach($fields as $print => $field){
	$$print = new table_field($print);
	$$print->onclick = "";
	if($print == 'No' || $print == 'Carte') $$print->styleclass = 'center';
	$table->fields[] = $$print;
}

foreach($salles as $no){
	$salle = new salle($no);
	$row = new table_row();
	$row->cols = array();
	foreach($fields as $print => $field){
		if($field == 'carte'){
			$td = $salle->lien('carte');
		}
		else{
			$tabs = explode(",",$field);
			$td = "";
			$i = 0;
			foreach($tabs as $tab){
				$td .= $salle->$tab;
				$td .= ($i++) ? " " : "<br />";
			}
		}
		$row->cols[$print] = ereg_replace("<br \/>$","",$td);
	}
	$table->rows[] = $row;
}
echo $table->print_header();
echo $table->print_body();
echo $table->print_footer();



$fields = array (
			"ID" => "id",
			"Fonction" => "fonction",
			"Nom" => "prenom,nom",
			"Adresse" =>  "adresse,npa,localite",
			"T&eacute;l&eacute;phones" => "tel,mobile",
			"Email" => "email");
foreach($commissions as $id => $nom){
	$commission = new commission($id);
	if($commission->visible){
		$text = (check_admin()) ? "<span class = 'fade float_right' style = 'font-size: 7pt'>d&eacute;placer les lignes pour ordonner</span>" : "";
		echo "<h2><a name = '$nom'></a>".(ucfirst($commission->description))."$text</h2>\n";
		$table = new table($nom);
		$table->filter = 0;
		if(check_admin() && is_ie6() == 0){
			$table->tbody_id = "table_content_".$nom;
			$table->sortable = "ID";
		}
		foreach($fields as $print => $field){
			$$print = new table_field($print);
			$$print->onclick = "";
			if($print == 'ID') $$print->hidden = 1;
			$table->fields[] = $$print;
		}
		foreach($commission->membres() as $membre_id => $fonction){
			$membre = new membre($membre_id);
			$row = new table_row();
			if(check_admin() && is_ie6() == 0) $row->onclick = "style = \"cursor: move\"";
			$row->cols = array();
			foreach($fields as $print => $field){
				if($print == 'Fonction'){
					$td = $fonction;
				}
				elseif($print == 'Email'){
	 				if($membre->site == 0) $membre->email = "";
					$td = print_email($membre->email);
				}
				elseif($print == 'ID'){
					$td = $membre_id;
				}
				else{
					if($membre->site == 0 && (strpos($field,"npa") !== FALSE)){
						$td = "<span class = 'fade'>&agrave; l'adresse<br />du club</span>";
					}
					elseif($membre->site == 0 && (strpos($field,"tel") !== FALSE)) $td = "";
					else{
						$tabs = explode(",",$field);
						$td = "";
						$i = 0;
						foreach($tabs as $tab){
							$td .= $membre->$tab;
							$td .= ($i++) ? " " : "<br />";
						}
					}
				}
				$row->cols[$print] = ereg_replace("<br \/>$","",$td);
			}
			$table->rows[] = $row;
		}
		echo $table->print_header();
		echo $table->print_body();
		echo $table->print_footer();
	}
}
echo "<h2><a name = 'responsables'></a>Responsables d'&eacute;quipe</h2>\n";
$equipes = liste('equipes',"nom","num");
$table = new table('responsables');
$table->filter = 0;
foreach($fields as $print => $field){
	if($print == 'Fonction') $print = 'Equipe';
	$$print = new table_field($print);
	if($field == 'id') $$print->hidden = 1;
	$$print->onclick = "";
	$table->fields[] = $$print;
}

foreach($equipes as $id => $nom){
	$equipe = new equipe($id);
	if(strpos($equipe->nom_complet,"(") !== FALSE){
		if(count($equipe->entraineurs)) $membre = new membre(array_shift(array_keys($equipe->entraineurs)));
		else $membre = new membre($equipe->responsable);
	}
	else $membre = new membre($equipe->responsable);
	$row = new table_row();
	$row->cols = array();
	foreach($fields as $print => $field){
		if($print == 'Fonction'){
			$print = "Equipe";
			$td = "<a href = 'equipes.php?id=$id'>".$nom."</a>";
		}
		elseif($print == 'Email'){
			$td = print_email($membre->email);
		}
		else{
			$tabs = explode(",",$field);
			$td = "";
			$i = 0;
			foreach($tabs as $tab){
				$td .= $membre->$tab;
				$td .= ($i++) ? " " : "<br />";
			}
		}
		$row->cols[$print] = ereg_replace("<br \/>$","",$td);
	}
	$table->rows[] = $row;
}
echo $table->print_header();
echo $table->print_body();
echo $table->print_footer();

echo "<h2><a name = 'comptes'></a>Comptes bancaires</h2>\n";
echo "<table class = 'wide'>\n";
echo "<tr><th>Banque Raiffeisen</th><th>Poste CCP</th></tr>\n";
echo "<tr>\n";
echo "<td class = 'center'  style = 'padding: 5px'>Banque Raiffeisen de Lavaux<br />1095 Lutry<br />CCP : 18-1616-9<br /><span class = 'bold'>IBAN : CH94 8045 4000 1000 3960 2</span><br />Volley Ball Club Lutry-Lavaux<br />CP 47<br />1095 Lutry</td>\n";
// echo "<td  class = 'center' style = 'padding: 5px'>Banque Cantonale Vaudoise<br />1001 Lausanne<br />CCP : 10-725-4<br /><span class = 'bold'>compte No : k 0631.94.45&nbsp;&nbsp;&nbsp;767</span><br />Volley Ball Club Lutry-Lavaux<br />P.a. Mme Sarah Liechti<br />Rue du Coll&egrave;ge<br />1071 Rivaz</td>\n";
echo "<td class = 'center' style = 'padding: 5px'>Volley-ball Club Lutry-Lavaux<br />1095 Lutry<br /><span class = 'bold'>CCP : 10-17300-6</span></td>\n";
echo "</tr>\n";
echo "</table>\n";

$liens = array(	"Swiss Volley R&eacute;gion Vaud", "Le volley-ball dans le canton de Vaud","http://www.svrv.ch",
				"Swiss Volley","Le volley-ball en Suisse","http://www.volleyball.ch",
				"CEV","Le volley-ball en Europe","http://www.cev.lu",
				"F&eacute;d&eacute;ration Internationale de Volley-Ball", "Le volleyball dans le Monde", "http://www.fivb.ch",
				"J&amp;S", "Jeunesse et Sports Volleyball","http://www.jugendundsport.ch/internet/js/fr/home/sportarten/volleyball.html");
echo "<h2><a name = 'liens'></a>Liens sur des sites de volley-ball</h2>\n";
echo "<table class = 'wide'>\n";
echo "<tr><th>Site</th><th>Description</th><th>Lien</th></tr>\n";
$i = 0;
while($i <  count($liens)){
	echo "<tr><td>$liens[$i]</td><td>".($liens[$i+1])."</td><td><a href = '".($liens[$i+2])."' target = '_blank'>".(preg_replace('/http:\/\/(.*?)\/.*/','http://\\1',$liens[$i+2]))."</a></td></tr>\n";
	$i+=3;
}
echo "</table>\n";


if(check_admin() && is_ie6() == 0){
	echo "<script type = 'text/javascript'>\n";
	foreach($commissions as $id => $nom){
		echo " Sortable.create('table_content_$nom',{tag:'tr',onUpdate:rank_$nom});\n";
	}
	echo "</script>\n";
}
pied();
?>
